"""

"""
# 导入包

import unittest
from unittestreport import ddt, list_data
from day16.handl_excel import Handlexcel
import openpyxl
from day16.register import register
#调用日志
from day16.hander_log import creat_log

mylog=creat_log()
workbook = openpyxl.load_workbook(r'D:\learn\day16\testcase\case01.xlsx')
sh = workbook['login']
res = list(sh.rows)
# 获取第一行的表头
# title=res[0]
# tvalue=[]
# for i in title:
#     tvalue.append(i)

title = [i.value for i in res[0]]
# 获取第一行之外的其他行
case = []
for item in res[1:]:
    data = [i.value for i in item]
    dic = dict(zip(title, data))
    case.append(dic)


@ddt
class Testregister(unittest.TestCase):
    # 调用操作excel的封装
    excel = Handlexcel(r'D:\learn\day16\testcase\case01.xlsx','login')
    # 调用excel读的方法
    case = excel.read_data()

    @list_data(case)
    def test_login(self, item):
        # 准备数据,读取的excel数据都是字符串的形式，需要去除引号
        expected = eval(item['expected'])
        params = eval(item['data'])
        result = item['case_id'] + 1
        # 调用功能函数，后去实际结果
        res = register(*params)
        # 断言
        try:
            self.assertEqual(expected, res)
        except AssertionError as e:
            self.excel.write_data(row=result,conlumn=5,value='false')
            mylog.error('用例{}执行失败'.format(item['title']))
            #1打印出粗的日志
            mylog.error(e)
            #2。打印详细的错误日志
            #mylog.exception(e)
            raise e
        else:
            self.excel.write_data(row=result, conlumn=5, value='true')
            mylog.error('用例{}执行成功'.format(item['title']))

